<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('售后管理列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li class="select-time">
                                <label>施工单日期：</label>
                                <input style="width: 200px;" type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginDdate]" data-format="yyyy-MM-dd HH:mm:ss"/>
                                <span>-</span>
                                <input style="width: 200px;" type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endDdate]" data-format="yyyy-MM-dd HH:mm:ss"/>
                            </li>
                            <li>
                                <label>施工单单号：</label>
                                <input type="text" name="code"/>
                            </li>
                            <li>
                                <label>VIN码：</label>
                                <input type="text" name="vin"/>
                            </li>
                            <li>
                                <label>车型：</label>
                                <input type="text" name="carstd"/>
                            </li>
                            <li>
                                <label>门店：</label>
                                <input type="text" name="shopname"/>
                            </li>
                            <li>
                                <label>售后次数：</label>
                                <input type="text" name="saleserviceTimes"/>
                                <span>--</span>
                                <input type="text" name="esaleserviceTimes"/>

                            </li>
                            <li>
                                <label>施工单状态：</label>
                                <select name="st">
                                    <option value="">所有</option>
                                    <option value="保存">保存</option>
                                    <option value="审核">审核</option>
                                </select>
                            </li>
                            <!--<li>
                                <label>售后次数：</label>
                                <input type="number" name="saleserviceTimes"/>
                            </li>-->
                            <li>
                                <label>是否存在换货：</label>
                                <select name="isChangeProduct">
                                    <option value="">所有</option>
                                    <option value="是">是</option>
                                    <option value="否">否</option>
                                </select>
                            </li>
                            <li>
                                <label>换货是否未处理：</label>
                                <select name="isChangeDeal">
                                    <option value="">所有</option>
                                    <option value="是">是</option>
                                    <option value="否">否</option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                               <!-- <a class="btn btn-warning btn-rounded btn-sm" onclick="exportQuery()"><i class="fa fa-download"></i>&nbsp;导出查询结果</a>-->
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <!--<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="erp:setupbill:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="erp:setupbill:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="erp:setupbill:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>-->
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="erp:setupbill:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('erp:setupbill:edit')}]];
        var removeFlag = [[${@permission.hasPermi('erp:setupbill:remove')}]];
        var prefix = ctx + "erp/setupbills";
        var prefix1 = ctx + "erp/saleservices";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix1 + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: ctx + "erp/saleservices/exportAll",
                modalName: "施工单信息",
                firstLoad: false,
                detailView: true,
                onExpandRow : function(index, row, $detail) {
                    initChildTable(index, row, $detail);
                },
                columns: [{
                    checkbox: true
                },
                {
                    field: 'ddate',
                    title: '施工单日期'
                },
                {
                    field: 'code',
                    title: '施工单单号'
                },
                {
                    field: 'ctype',
                    title: '施工单种类'
                },
                {
                    field: 'shopname',
                    title: '销售仓库'
                },
                {
                    field: 'vin',
                    title: 'VIN码'
                },
                {
                    field: 'vinpic',
                    title: 'VIN图片',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a  href="javascript:void(0)" onclick="openVinPic(\'' + row.vinpic + '\')">查看</a> ');
                        return actions.join('');
                    }
                },
                {
                    field: 'carstd',
                    title: '车型'
                },
                {
                    field: 'setuppic',
                    title: '安装后的图片',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a  href="javascript:void(0)" onclick="openSetupPic(\'' + row.setuppic + '\')">查看</a> ');
                        return actions.join('');
                    }
                },
                {
                    field: 'pcode',
                    title: '产品代码'
                },
                {
                    field: 'pname',
                    title: '产品名称'
                },
                {
                    field: 'pstd',
                    title: '产品规格'
                },
                {
                    field: 'punit',
                    title: '单位'
                },
                {
                    field: 'serviceTimes',
                    title: '售后次数'
                },
                {
                    field: 'isChangeProduct',
                    title: '是否存在换货'
                },
                {
                    field: 'isChangeDeal',
                    title: '换货是否未处理'
                },
                {
                    field: 'memo',
                    title: '备注'
                }]
            };
            $.table.init(options);
        });
        initChildTable = function(index, row, $detail) {
            var childTable = $detail.html('<table style="table-layout:fixed"></table>').find('table');
            $(childTable).bootstrapTable({
                url: prefix + "/listSaleService",
                modalName: "销售产品",
                method: 'post',
                sidePagination: "server",
                contentType: "application/x-www-form-urlencoded",
                queryParams : {
                    mid: row.id
                },
                columns: [
                    {
                        field: 'ddate',
                        title: '售后服务日期'
                    },
                    {
                        field: 'shopname',
                        title: '售后门店'
                    },
                    {
                        field: 'ctype',
                        title: '类型'
                    },
                    {
                        field: 'sericedesc',
                        title: '服务内容记录'
                    },
                    {
                        field: 'emp',
                        title: '操作员'
                    },
                    {
                        field: 'st',
                        title: '状态'
                    },
                    {
                        field: 'dealemp',
                        title: '换货处理人'
                    },
                    {
                        field: 'dealdt',
                        title: '换货处理日期'
                    },
                    {
                        field: 'smemo',
                        title: '备注'
                    },
                    {
                        title: '操作',
                        align: 'center',
                        formatter: function(value, row, index) {
                            var actions = [];
                            if(row.st == '未处理' && row.ctype == '换货'){
                                actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                                actions.push('<a class="btn btn-warning btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="review(\'' + row.id + '\')"><i class="fa fa-edit"></i>处理</a> ');
                            }else
                            if(row.st =='已处理' && row.ctype == '换货'){
                                actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                                actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="disReview(\'' + row.id + '\')"><i class="fa fa-remove"></i>撤销处理</a>');
                            }else{
                                actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            }
                            return actions.join('');
                        }
                    }]
            });

        };
        function review(id) {
            debugger;
            $.ajax({
                type: "post",
                url: ctx + "erp/saleservices/reviewSaleService?id="+id,
                success: function(r) {
                    $.modal.msgSuccess("处理成功");
                }
            });
            $("#bootstrap-table").bootstrapTable('refresh', {
                silent: true
            });
        }

        function disReview(id) {
            debugger;
            $.ajax({
                type: "post",
                url: ctx + "erp/saleservices/disReviewSaleService?id="+id,
                success: function(r) {
                    $.modal.msgSuccess("撤销成功");
                }
            });
            $("#bootstrap-table").bootstrapTable('refresh', {
                silent: true
            });
        }

        function openVinPic(vinpic){
            $.modal.open("查看图片", "http://www.gdhbsfndzkj.cn:8780"+vinpic);
        }
         function openSetupPic(setuppic){
            $.modal.open("查看图片", "http://www.gdhbsfndzkj.cn:8780"+setuppic);
        }

        function exportQuery(){
            debugger;
            var rows=$('#bootstrap-table').bootstrapTable('getData');
            var rowsId ='';
            for(var i=0;i<rows.length;i++) {
                if (i != rows.length - 1) {
                    rowsId += rows[i].id + ",";
                } else {
                    rowsId += rows[i].id;
                }
            }
            $.modal.confirm("确定导出" + table.options.modalName + "吗？", function() {
                debugger;
                var params = $("#" + table.options.id).bootstrapTable('getOptions');
                var dataParam = $("#bootstrap-table").serializeArray();
                dataParam.push({ "name": "orderByColumn", "value": params.sortName });
                dataParam.push({ "name": "isAsc", "value": params.sortOrder });
                $.modal.loading("正在导出数据，请稍后...");
                $.post(ctx + "erp/saleservices/exportQuery?rowsId="+rowsId, dataParam, function(result) {
                    debugger;
                    if (result.code == web_status.SUCCESS) {
                        window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
                    } else if (result.code == web_status.WARNING) {
                        $.modal.alertWarning(result.msg)
                    } else {
                        $.modal.alertError(result.msg);
                    }
                    $.modal.closeLoading();
                });
            });
        }
    </script>
</body>
</html>